<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('账户入账申请列表')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list row">
                        <ul>
                            <li>
                                <label>申请ID：</label>
                                <input type="text" name="id"/>
                            </li>
                            <li>
                                <label>申请日期：</label>
                                <input type="text" name="dateInfo" id="dateInfo" autocomplete="off"/>
                            </li>
                            <li>
                                <label>子账户类型：</label>
                                <select name="itemAccountType" class="form-control">
                                    <option value="">所有</option>
                                    <option  th:each="item:${accountTypeList}" th:text="${item.name}" th:value="${item.value}"></option>
                                </select>
                            </li>
                            <li>
                                <label>子账户名称：</label>
                                <input type="text" name="itemAccountName"/>
                            </li>
                        </ul>
                    </div>
                    <div class="select-list row">
                    <ul>
                        <li>
                            <label>状态：</label>
                            <select name="status" class="form-control">
                                <option value="">所有</option>
                                <option  th:each="item:${statusList}" th:text="${item.name}" th:value="${item.value}"></option>
                            </select>
                        </li>
                        <li>
                            <label>操作类型：</label>
                            <select name="actionType" class="form-control">
                                <option value="">所有</option>
                                <option  th:each="item:${actionTypeList}" th:text="${item.name}" th:value="${item.value}"></option>
                            </select>
                        </li>
<!--                            <li>-->
<!--                                <label>总账户信息：</label>-->
<!--                                <select name="mainAccountId" class="form-control">-->
<!--                                    <option value="">所有</option>-->
<!--                                    <option  th:each="item:${accountInfoList}" th:text="${item.name}" th:value="${item.value}"></option>-->
<!--                                </select>-->
<!--                            </li>-->

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="account:record:add">
                    <i class="fa fa-plus"></i> 添加入账申请
                </a>
<!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="account:record:edit">-->
<!--                    <i class="fa fa-edit"></i> 修改-->
<!--                </a>-->
<!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="account:record:remove">-->
<!--                    <i class="fa fa-remove"></i> 删除-->
<!--                </a>-->
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="account:record:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('account:record:edit')}]];
        var removeFlag = [[${@permission.hasPermi('account:record:remove')}]];
        var enterFlag = [[${@permission.hasPermi('account:record:enter')}]];
        var applyFlag = [[${@permission.hasPermi('account:record:applyEnter')}]];
        var prefix = ctx + "account/record";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                detailUrl: prefix + "/detail/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "账户入账申请",
                columns: [
                //     {
                //     checkbox: true
                // },
                {
                    field: 'id',
                    title: '申请ID',
                },
                {
                    field: 'billDateInfo',
                    title: '账单日期'
                },
                    {
                        field: 'itemAccountTypeStr',
                        title: '子账户信息',
                        formatter: function (value,row,index){
                            return row.itemAccountTypeStr + '-' + row.itemAccountName + ' 【 ' + row.actionTypeStr + ' 】';
                        }
                    },
                //     {
                //         field: 'itemAccountTypeStr',
                //         title: '子账户类型',
                //     },
                // {
                //     field: 'itemAccountName',
                //     title: '子账户名称'
                // },
                // {
                //     field: 'actionTypeStr',
                //     title: '操作类型',
                //
                // },
                {
                    field: 'mainAccountName',
                    title: '总账户名称'
                },
                {
                    field: 'billAmount',
                    title: '入账金额'
                },
                {
                    field: 'imgUrl',
                    title: '图片信息',
                    formatter: function (value,row,index){
                        // return  '<a href="'+row.imgUrl+'" target="_blank" />'+$.table.imageView(row.imgUrl, 500, 500, '_blank')+'</a>';
                        return  $.table.imageView(row.imgUrl, 500, 500);
                    }
                },
                    {
                        field: 'remarkInfo',
                        title: '备注',
                        formatter: function (value,row,index) {
                            return $.table.tooltip(value);
                        }
                    },
                {
                    field: 'statusStr',
                    title: '状态',
                },
                {
                    field: '-',
                    title: '操作员',
                    formatter: function (value,row,index){
                        var content = '';
                        if (row.creatorName != undefined && row.creatorName != ''){
                            content = content + '创建：' + row.creatorName + '<br>';
                        }
                        if (row.updatorName != undefined && row.updatorName != ''){
                            content = content + '入账：' + row.updatorName;
                        }
                        return content;
                    }
                },
                {
                    field: 'createTime',
                    title: '操作时间',
                    formatter: function (value,row,index){
                        var content = '';
                        if (row.createTime != undefined && row.createTime != ''){
                            content = content + '创建：' + row.createTime + '<br>';
                        }
                        if (row.updateTime != undefined && row.updateTime != ''){
                            content = content + '入账：' + row.updateTime;
                        }
                        return content;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];

                        var name = row.itemAccountTypeStr + '-' + row.itemAccountName + '-' + row.actionTypeStr;

                        // 待确认的
                        if (row.status == 0 ){
                            actions.push('<a class="btn btn-primary btn-xs ' + applyFlag + '"  onclick=applyEnter(\'' + row.id + '\',\'' + name + '\')><i class="fa fa-align-center"></i>申请入账</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                            // 编辑和删除权限的时候，显示详情
                        }else if (row.status == 1 ){
                            actions.push('<a class="btn btn-primary btn-xs ' + enterFlag + '" onclick=enterAccount(\'' + row.id + '\',\'' + name + '\')><i class="fa fa-align-center"></i>入账</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + enterFlag + '"  onclick=refuseEnter(\'' + row.id + '\',\'' + name + '\')><i class="fa fa-remove"></i>驳回</a> ');
                        }else{
                            actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="$.operate.detailUrl(\'' + row.id + '\')"><i class="fa fa-desktop"></i>详情</a> ');
                        }

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        layui.use('laydate', function(){
            var laydate = layui.laydate;

            laydate.render({
                elem: '#dateInfo',
                type: 'date',
                range: ' ~ '
            });

        });

        /**
         * 确认入账
         * @param recordId
         * @param recordName
         */
        function enterAccount(recordId, recordName){
            $.modal.confirm("确定入账该条[" + recordName + "]申请信息吗？", function() {
                    var url = prefix + '/enterAccount'
                    $.operate.post(url,{recordId: recordId});
            });
        }

        /**
         * 驳回入账申请
         * @param recordId
         * @param recordName
         */
        function refuseEnter(recordId, recordName){
            $.modal.confirm("确定驳回该条[" + recordName + "]申请信息吗？", function() {
                var url = prefix + '/refuseEnter'
                $.operate.post(url,{recordId: recordId});
            });
        }

        /**
         * 申请入账
         * @param recordId
         * @param recordName
         */
        function applyEnter(recordId, recordName){
            $.modal.confirm("确定申请入账该条[" + recordName + "]申请信息吗？", function() {
                var url = prefix + '/applyEnter'
                $.operate.post(url,{recordId: recordId});
            });
        }

    </script>
</body>
</html>